package com.lizhi.menu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.CarDto;
import com.lizhi.menu.domain.Car;
import com.lizhi.menu.mapper.CarMapper;
import com.lizhi.menu.service.ICarService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 购物车Service业务层处理
 *
 * @author lizhi
 * @date 2023-05-18
 */
@Service
@RequiredArgsConstructor
public class CarServiceImpl implements ICarService {
    private final CarMapper carMapper;

    /**
     * 查询购物车
     *
     * @param id 购物车主键
     * @return 购物车
     */
    @Override
    public Car getInfo(Long id) {
        return carMapper.selectById(id);
    }

    /**
     * 查询购物车列表
     *
     * @param car 购物车
     * @return 购物车
     */
    @Override
    public Page<Car> list(CarDto car) {
        return carMapper.selectCarList(car.createPage(),car);
    }

    /**
     * 新增购物车
     *
     * @param car 购物车
     * @return 结果
     */
    @Override
    public int add(Car car) {
        return carMapper.insert(car);
    }

    /**
     * 修改购物车
     *
     * @param car 购物车
     * @return 结果
     */
    @Override
    public int edit(Car car) {
        return carMapper.updateById(car);
    }

    /**
     * 批量删除购物车
     *
     * @param ids 需要删除的购物车主键
     * @return 结果
     */
    @Override
    public int remove(List<String> ids) {
        return carMapper.deleteCarByIds(ids);
    }

    /**
     * 删除购物车信息
     *
     * @param id 购物车主键
     * @return 结果
     */
    @Override
    public int remove(String id) {
        return carMapper.deleteById(id);
    }
}
